/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

function validateFormGeraRelatDesp(theForm)
{
    if (theForm.idPac.value == "" && 
        theForm.idEstab.value == "" && 
        theForm.idTipoDesp.value == "" &&
        theForm.dataIni.value == "" &&
        theForm.dataFim.value == "")
    {
        alert("Preencha ao menos um campo!");
        return false;
    }
    
    if (!isEmpty(theForm.dataIni,"Data Inicial"))
      if (!validDate(theForm.dataIni,"Data Inicial",false))
	return false;

    if (!isEmpty(theForm.dataFim,"Data Final"))
      if (!validDate(theForm.dataFim,"Data Final",false))
	return false;

    if (!isEmpty(theForm.dataIni,"Data Inicial") && !isEmpty(theForm.dataFim,"Data Final"))
      if(theForm.dataIni.value > theForm.dataFim.value) {
          alert('Data final deve ser menor que data inicial!')
          return false;
      }

    return true;
}

function validateFormPac(theForm)
{
        var dataN = new Date;
        var dataF = new Date;

        if (!validRequired(theForm.nome,"Nome"))
		return false;

	if (!validRequired(theForm.cpf,"CPF",true))
		return false;
	else {
		if (!ValidarCPF(theForm.cpf)) {
			theForm.cpf.focus();
			return false;
		}
	}

	if (!isEmpty(theForm.email,"E-Mail"))
		if (!validEmail(theForm.email,"E-Mail",true))
			return false;

	if (!isEmpty(theForm.cep,"CEP"))
                if (!ValidaCep(theForm.cep))
                        return false;

	if (!isEmpty(theForm.fone,"Telefone"))
                if(!ValidaTelefone(theForm.fone))
                        return false;

	if (!isEmpty(theForm.dataNasc,"Data Nasc."))
		if (!validDate(theForm.dataNasc,"Data Nasc.",true))
			return false;

	if (!isEmpty(theForm.dataFalec,"Data Falec."))
		if (!validDate(theForm.dataFalec,"Data Falec.",true))
			return false;
    
//        if(!isEmpty(theForm.dataNasc,"Data Nasc.") && !isEmpty(theForm.dataFalec,"Data Falec.")) {
//          dataN = theForm.dataNasc.value;
//          dataF = theForm.dataFalec.value;
//
//          if(dataN > dataF) {
//              alert('Data de falecimento deve ser menor que a data de nascimento.');
//              return false;
//          }
//        }
    
        return true;
}

function validateFormEstab(theForm)
{
	if (!validRequired(theForm.nomeFantasia,"Nome"))
		return false;

	if (!validRequired(theForm.cnpj,"CNPJ",true))
		return false;
	else
	{
		if (!ValidarCNPJ(theForm.cnpj))
		{
			alert("Valor invalido de CNPJ!")

			theForm.cpf.focus();
			return false;
		}
	}

	if (!isEmpty(theForm.email,"E-Mail"))
		if (!validEmail(theForm.email,"E-Mail",true))
			return false;

	if (!isEmpty(theForm.fone,"Telefone"))
                if(!ValidaTelefone(theForm.fone))
                        return false;

	if (!isEmpty(theForm.cep,"CEP"))
                if (!ValidaCep(theForm.cep))
                        return false;

        return true;
}

function validateFormTipoDesp(theForm)
{
	if (!validRequired(theForm.descricao,"Descricao"))
		return false;
	return true;
}

function validateFormDesp(theForm)
{

    if (!validRequired(theForm.estab,"Estabelecimento"))
      return false;
    
    if (!validRequired(theForm.paciente,"Paciente"))
      return false;
        
    if (!validRequired(theForm.tipoDesp,"Tipo Despesa"))
      return false;

    if (!validRequired(theForm.dataDesp,"Data Despesa"))
      return false;
    else
      if (!validDate(theForm.dataDesp,"Data Despesa",false))
          return false;
            
    if (!validRequired(theForm.valorDesp,"Valor Despesa"))
      return false;
            
    return true;
}

function validateFormRec(theForm)
{

    if (!validRequired(theForm.idDesp,"Despesa"))
      return false;
    
    if (!validRequired(theForm.idPac,"Paciente"))
      return false;
        
    if (!validRequired(theForm.dataRec,"Data Recibo"))
      return false;
    else
      if (!validDate(theForm.dataRec,"Data Recibo",true))
          return false;
            
    if (!validRequired(theForm.valorDesp,"Valor"))
      return false;

    return true;
}

function validateFormAut(theForm)
{

    if (!validRequired(theForm.idPac,"Paciente"))
      return false;

    if (!validRequired(theForm.idEstab,"Estabelecimento"))
      return false;

    if (!validRequired(theForm.dataAut,"Data Autorizacao"))
      return false;
    else
      if (!validDate(theForm.dataAut,"Data Autorizacao",true))
          return false;

    return true;
}

function validateFormBDInstall(theForm)
{
	if (!validRequired(theForm.user,"Usuario"))
		return false;

	if (!validRequired(theForm.server,"Servidor"))
		return false;

	return true;
}
